home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / mc51bugs / q32017 < prev    next >
Text File  |  1988-07-20  |  2KB  |  54 lines

  1. Q32017 _Lrotl, _Lrotr Produce Incorrect Results when Compiled /Oi
  2. C Compiler
  3. 5.10   | 5.10
  4. MS-DOS | OS/2
  5.  
  6. Summary:
  7.    The intrinsic form of _lrotr and _lrotl produces incorrect code
  8. when the result of the functions is assigned to an unsigned integer.
  9. The correct output for the program below is as follows:
  10.  
  11.    3
  12.    0
  13.  
  14.    When compiled with /Oi (enables intrinsic functions), the output
  15. for the program is as follows:
  16.  
  17.    2
  18.    8000
  19.  
  20. More Information:
  21.    The program is as follows:
  22.  
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. main()
  26. {
  27.   unsigned b;
  28.   unsigned c;
  29.   b = _lrotl(0x80000001L,1);     /* rotate the hex value
  30.                                     80000001 one bit to the
  31.                                     left */
  32.   c = _lrotr(0x80000001L,1);     /* rotate one bit to the
  33.                                     right  */
  34.   printf("%x\n",b);
  35.   printf("%x\n",c);
  36. }
  37.  
  38.    The optimization erroneously causes the rotation to be performed on
  39. an unsigned short rather than the designated unsigned long.
  40.    To work around this problem, type cast the result of the rotate
  41. functions to an unsigned long before the assignment, as follows:
  42.  
  43.     b = (unsigned long)_lrotl(0x80000001L,1);
  44.     c = (unsigned long)_lrotr(0x80000001L,1);
  45.  
  46.    Microsoft has confirmed this to be a problem in Version 5.10 of the
  47. C compiler. Microsoft is researching this problem and will post new
  48. information as it becomes available.
  49.  
  50.  
  51.  
  52. Keywords:  buglist5.10
  53. Updated  88/07/21 03:19
  54.